package com.sk.weichat.ui.me.wallet.viewmode;

import android.util.Log;
import com.sk.weichat.ui.base.CoreManager;
import com.sk.weichat.ui.me.wallet.view.RealNameAuthenticationView;
import com.xuan.xuanhttplibrary.okhttp.HttpUtils;
import com.xuan.xuanhttplibrary.okhttp.callback.BaseCallback;
import com.xuan.xuanhttplibrary.okhttp.result.ObjectResult;
import java.util.HashMap;
import java.util.Map;
import okhttp3.Call;

public class RealNameAuthenticationViewMode {

    private RealNameAuthenticationView mRealNameAuthenticationView;
    private CoreManager coreManager;


    public RealNameAuthenticationViewMode(CoreManager coreManager,RealNameAuthenticationView mRealNameAuthenticationView) {
        this.mRealNameAuthenticationView = mRealNameAuthenticationView;
        this.coreManager = coreManager;
    }

    /**
    * 获取阿里云token
    * */
    public void getAliyunToken(){
        mRealNameAuthenticationView.showProgress();
        Map<String, String> params = new HashMap<>();
        params.put("access_token", coreManager.getSelfStatus().accessToken);
        HttpUtils.post().url(coreManager.getConfig().AIYUN_TOKEN)
                .params(params)
                .build()
                .execute(new BaseCallback<String>(String.class) {
                    @Override
                    public void onResponse(ObjectResult<String> result) {
                        mRealNameAuthenticationView.getAliyunTokenResult(result);
                        mRealNameAuthenticationView.hideProgress();
                    }
                    @Override
                    public void onError(Call call, Exception e) {
                        mRealNameAuthenticationView.hideProgress();
                    }
                });
    }

    /**
    * 阿里云认证回调
    * */
    public void AiyunAuthBack(String aliYunStatus){
        mRealNameAuthenticationView.showProgress();

        Map<String, String> params = new HashMap<>();
        params.put("access_token", coreManager.getSelfStatus().accessToken);
        params.put("aliYunStatus", aliYunStatus);
        HttpUtils.post().url(coreManager.getConfig().AIYUN_AUTH_BACK)
                .params(params)
                .build()
                .execute(new BaseCallback<String>(String.class) {
                    @Override
                    public void onResponse(ObjectResult<String> result) {
                        mRealNameAuthenticationView.AiyunAuthBackResult(result);
                        mRealNameAuthenticationView.hideProgress();
                    }
                    @Override
                    public void onError(Call call, Exception e) {
                        Log.e("AiyunAuthBack", "Exception", e);
                        mRealNameAuthenticationView.hideProgress();

                    }
                });
    }
}
